"""
1.导入pymysql
2.创建连接对象
3.获取游标对象
4.执行sql语句
5.提交或回滚(事务)
6.关闭游标对象
7.关闭连接对象
"""
import pymysql

conn = pymysql.connect(host='localhost', user='root', password='root', database='advanced', port=3306, charset='utf8')

cursor = conn.cursor()

try:
    sql = "insert into student(stu_id,stu_no,stu_name,stu_score) values(7,'itsrc-015','吕布',65)"
    # sql = 'insert into student(stu_id,stu_no,stu_name,stu_score) values(7,\'itsrc-015\',\'吕布\',65)'
    rows = cursor.execute(sql)
    print('受影响的行数:%d' % rows)
except Exception as e:
    print(e)
    conn.rollback()
else:
    conn.commit()

cursor.close()
conn.close()


